namespace CGF
{
    public partial class PanelTextDetail : UIComponentBase, IAwake<UILayer, bool>, IDestroy
    {
        private string title, content;
        
        public static void Open(string title, string content)
        {
            PanelTextDetail instance = UIManagerComponent.instance.OpenUI<PanelTextDetail>(UILayer.Normal, RootComponent.instance, false);
            instance.SetInfo(title, content);
        }

        public static void Close()
        {
            UIManagerComponent.instance.CloseUI<PanelTextDetail>();
        }

        public async void Awake(UILayer layer, bool isFloat)
        {
            await SpawnPrefab("Prefabs/GameUI/PanelTextDetail", layer, isFloat);
			BindProperties(transform);
            
            BtnBack.SetClick(Close);

            if (!string.IsNullOrEmpty(title))
            {
                SetInfo(title, content);
            }
        }

        private void SetInfo(string title, string content)
        {
            this.title = title;
            this.content = content;
            if (Title)
            {
                Title.text = title;
                Content.text = content;
            }
        }

        public override void OnDestroy()
        {
            base.OnDestroy();
        }

    }
}
